#!/usr/bin/env python3

'''
The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual in two ways: (i) each of the three terms are prime, and, (ii) each of the 4-digit numbers are permutations of one another.

There are no arithmetic sequences made up of three 1-, 2-, or 3-digit primes, exhibiting this property, but there is one other 4-digit increasing sequence.

What 12-digit number do you form by concatenating the three terms in this sequence?
'''

from euler import *
from itertools import permutations

p = getprimes(9999)
primes = set()
for prime in p:
    if prime > 999:
        primes.add(prime)

for prime in primes:
    current = set()
    for perm in permutations(str(prime)):
        if ltoi(perm) in primes:
            current.add(ltoi(perm))
    if len(current) > 2:
            current = sorted(list(current))
            for x in range(len(current)-2):
                if current[x+2]-current[x+1] == current[x+1]-current[x]:
                    print(str(current[x])+","+str(current[x+1])+","+str(current[x+2]))